from instruction import Instruction

class Program:
    
    
    def __init__(self, sourceCode, name, priority):
        self.sourceCode = sourceCode
        self.name = name
        self.priority = priority
        self.programSize = len(self.sourceCode)
        
    def __repr__(self):
        return 'Prog "%s" %s' % (self.name, self.sourceCode)
    
    def programParts (self, pageSize):
        tempList = []
        returnList = []
        for elem in self.sourceCode:
            tempList.append(elem)
        while tempList is not []:
            tempPageSize = pageSize
            subList=[]
            while tempPageSize>0 and tempList is not []:
                subList.append(tempList.pop())
                tempPageSize -=1
            returnList.append(subList)
            
        return returnList
        
def main():
    
    n1 = 'A.c';
    prog = Program([Instruction('CPU', n1),Instruction('CPU', n1),Instruction('IO', n1), Instruction('CPU', n1), Instruction('END', n1)], n1, 1)

    print prog
    print prog.name
    print prog.priority
    print prog.programSize
    print prog.sourceCode
    print prog.programParts(2)
        
if __name__ == "__main__":
    main()
            